package aip.assignment2.service.entity;

import aip.assignment2.persistence.entity.Product;
import java.math.BigDecimal;

/**
 * This class is the entity that contains information of a product in the shopping cart
 */
public class ProductInCart
{
	public ProductInCart()
	{
	}
	public ProductInCart(Product product)
	{
		this.product = product;
		this.quantity = 1;
	}
	public ProductInCart(Product product, int quantity)
	{
		this.product = product;
		this.quantity = quantity >= 0 ? quantity : -quantity;
	}
	/**
	 * the product info
	 */
	private Product product;
	/**
	 * the quantity of the product
	 */
	private int quantity;
	/**
	 * the product info
	 * @return the product
	 */
	public Product getProduct()
	{
		return product;
	}
	/**
	 * the product info
	 * @param product the product to set
	 */
	public void setProduct(Product product)
	{
		this.product = product;
	}
	/**
	 * the quantity of the product
	 * @return the quantity
	 */
	public int getQuantity()
	{
		return quantity;
	}
	/**
	 * the quantity of the product
	 * @param quantity the quantity to set
	 */
	public void setQuantity(int quantity)
	{
		this.quantity = quantity;
	}
	/**
	 * the total price of the products
	 */
	public BigDecimal getPrice()
	{
		return product.getPrice().multiply(new BigDecimal(quantity));
	}
}
